package com.beerandjesus.sportofkings.handicapper.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Date: Jun 8, 2012
 * Time: 1:11:32 PM
 */
public class ConnectionManagerImpl implements ConnectionManager {

    private String turfSireDatabaseFile;

    public Connection getTurfSireDatabaseConnection() {
        try {
            return DriverManager.getConnection("jdbc:hsqldb:" + getTurfSireDatabaseFile(), "SA", "");
        } catch (SQLException e) {
            throw new DatabaseException("Error getting connection to the turf sire database", e);
        }
    }

    public void releaseConnection(Connection connection) {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                // Ignore this for now
            }
        }
    }

    public String getTurfSireDatabaseFile() {
        return turfSireDatabaseFile;
    }

    public void setTurfSireDatabaseFile(String turfSireDatabaseFile) {
        this.turfSireDatabaseFile = turfSireDatabaseFile;
    }
}
